﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XnaGameStudio1.Engine
{
    //-----------------------------------------------------------------------------------------------
    class Mesh<T> where T: struct
    {
        VertexBuffer vertexBuffer;
        IndexBuffer indexBuffer;
        int vertexCount;
        int indexCount;

        //-------------------------------------------------------------------------------------------
        public Mesh(List<T> vertices, UInt16[] indices)
        {
            // Create Vertex buffer
            vertexCount = vertices.Count;
            Debug.Assert(vertexCount > 0);            
            vertexBuffer = new VertexBuffer(
                XnaGraphicsDevice.Device, typeof(T), vertices.Count, BufferUsage.None
                );

            vertexBuffer.SetData<T>(vertices.ToArray());

            //Create Index buffer if there is
            indexCount = indices.Count();
            if (indexCount > 0)
            {
                indexBuffer = new IndexBuffer(
                    XnaGraphicsDevice.Device, typeof(Int16), indices.Count(), BufferUsage.None
                    );
            }


        }
    }
}
